<?php $this->load->view('sys_header');?>
<style type="text/css">
     /*datagrid样式*/
    .datagrid-header-row td{ line-height: 24px; height: auto;}
    .datagrid-btable td{ line-height: 24px; height: auto;}

</style>
<script type="text/javascript">
lin.ns('lin.admin.tclass');

$(function(){
    lin.admin.tclass.searchform = $('#info_searchform').form();
    lin.admin.tclass.editrow = undefined;
    $('#info_list').treegrid({
        url:'<?php echo made_admin_url('tclass/rows?tbname='.$this->tbname); ?>',
        idField:'classid',
        treeField:'classname',
        fitColumns:true,
        border:false,
        rownumbers: true,
        collapsible:true,
        style:"background: #fff",
        loadMsg : '数据载入中......',
        sortName:'order',
        sortOrder:'asc',
        onLoadError : function() {
            alert('数据加载失败!');
        },
        columns:[[

            {field:'classid',title:'栏目ID',width:15,align:'center'},
            {field:'classname',title:'分类名称',width:60,editor:{type:'validatebox',options:{}}},
            {field:'bname',title:'分类别名',width:60,align:'center',editor:{type:'validatebox',options:{}}},
            {field:'islast',title:'终极栏目',width:50,align:'center',
                formatter:function(value){
                if (value == '1') return '是';
                if (value == '0') return '否';
                },
                editor:{
                    "type":"checkbox",
                    "options":{
                        "on":'1',
                        "off":'0'
                    }
                }
            },

            {field:'checkpl',title:'评论',align:'center',width:30,
                formatter:function(value){
                    if (value == '1') return '允许';
                    if (value == '0') return '不允许';
                },
                editor:{
                    "type":"checkbox",
                    "options":{
                        "on":'1',
                        "off":'0'
                    }
                }
            },

            {field:'tbname',title:'所属类型',sortable:true,align:'center',width:30,

                formatter:function(value){

                        if (value == 'news') return '文章系统';
                        if (value == 'product') return '产品系统';
                        if (value == 'info') return '单页系统';

                }
            },
            {field:'order',title:'排序',width:20,sortable:true,align:'center',
                editor:{
                    type:'validatebox',
                    options:{

                    }
                }
            }
        ]],

        toolbar:[{
            text:"添加",
            iconCls:'icon-add',
            handler:function(){
                window.location.href = '<?php echo made_admin_url('tclass/addclass?tbname='.$this->tbname);?>';
                return false; //hack ie6跳转无效
            }
        },'-',{
            text:"修改",
            iconCls:'icon-edit',
            handler:function(){

                var rows = $('#info_list').treegrid('getSelections');
                if(rows.length == 1)
                {

                    //跳转到编辑页面
                    window.location.href = '<?php echo made_admin_url('tclass/editmore?tbname='.$this->tbname.'&id=');?>'+rows[0]['classid'];
                    return false; //hack ie6跳转无效

                }else if(rows.length == 0)
                {
                    lin.msg('没有选择数据！','error');
                    return;
                }else if(rows.length > 1)
                {
                    lin.msg('一次只能修改一条数据！','error');
                    return;
                }
            }
        },'-',{
            text:"删除",
            iconCls:'icon-remove',
            handler:function(){
                var rows = $('#info_list').treegrid('getSelections');
                if(rows.length > 0)
                {
                    $.messager.confirm('请确认','您确定要删除当前所选择的记录吗？',function(r){
                        if(r)
                        {

                            var id_arr = [];
                            for( var i = 0 ; i < rows.length; i++){
                                id_arr.push(rows[i].classid);
                            }

                            $.ajax({
                                type:'post',
                                url:'<?php echo made_admin_url('tclass/del');?>',
                                data:{id_arr:id_arr.join(',')},
                                dataType:"json",
                                success:function(r){
                                    if(r && r.success)
                                    {
                                        lin.msg('删除记录成功！');
                                        $('#info_list').treegrid('reload');
                                        $('#info_list').treegrid('unselectAll');    //取消所有选择

                                    }
                                    else
                                    {
                                        lin.msg(r.msg,'error');
                                    }

                                }

                            });
                        }
                        else
                        {

                        }
                    });
                }
                else
                {
                    lin.msg('请选择要删除的记录！','error');
                }
            }
        },'-',{
            text:"刷新",
            iconCls:'icon-reload',
            handler:function(){
                $('#info_list').treegrid('reload');
            }
        },'-',{
            text:"保存",
            iconCls:'icon-save',
            handler:function(){
                $('#info_list').treegrid('endEdit',lin.admin.tclass.editrow);
            }
        },'-',{
            text:"撤销",
            iconCls:'icon-redo',
            handler:function(){
                lin.admin.tclass.editrow = undefined;
                $('#info_list').treegrid('rejectChanges'); //回滚编辑前状态
                //$('#info_list').datagrid('cancelEdit');    //取消所有选择
                $('#info_list').treegrid('unselectAll');   //取消所有选择
                $('#info_list').treegrid('reload');        //刷新
            }
        },'-'

        ],

        buttons:[{iconCls:'icon-redo',handler:function(){}}],



        onAfterEdit:function(row,changes){


            if(changes.length != 0) //判断是否有修改
            {
                url = '<?php echo made_admin_url('tclass/edit');?>';

                //提交数据到后台
                $.ajax({
                    type:"post",
                    dataType: "json",//返回json格式的数据
                    url: url,
                    data: row,
                    success: function(r){
                        if(r && r.success)
                        {
                            $('#info_list').treegrid('acceptChanges');
                            $('#info_list').treegrid('load'); //刷新数据
                            lin.msg(r.msg,'info');

                        }
                        else
                        {
                            $('#info_list').treegrid('rejectChanges');
                            lin.msg(r.msg,'error');
                            $('#info_list').treegrid('load');    //刷新
                        }
                        lin.admin.tclass.editrow = undefined;
                        $('#info_list').treegrid('unselectAll');    //取消所有选择
                    }
                });


            }




        },

        onDblClickRow:function(rowIndex, rowData){

            if(lin.admin.tclass.editrow != undefined)
            {
                $('#info_list').treegrid('endEdit',lin.admin.tclass.editrow);
            }
            else
            {
                var node = $('#info_list').treegrid('getSelected');
                if (node){
                    $('#info_list').treegrid('beginEdit',node.classid);
                }
                lin.admin.tclass.editrow = node.classid;

            }
        }
        //onClickCell:function(rowIndex, field, value){
        //alert(value);
        //}

    });


});
function fixWidth(percent)
{
    return document.body.clientWidth * percent ; //这里你可以自己做调整
}

info_search = function(){
    $('#info_list').treegrid('reload',lin.serializeObject(lin.admin.tclass.searchform));
}


</script>

<div id="showpic"  title="My Window">
</div>

<div class="nav">
    <h2><a href="<?php echo made_admin_url('main/mainfra');?>">TAYCMS后台管理</a> >  <a href="<?php echo made_admin_url('tclass');?>">分类管理</a> </h2>
</div>


<div class="search">

    <div class="ml"></div>

</div>


<div class="list_warp">

    <div class="content_list" style=" border: 1px #ccc solid; ">
        <table id="info_list" ></table>
    </div>


</div>





<?php $this->load->view('sys_footer');?>